//
//  BestScore.m
//  Beat Bin Laden
//
//  Created by How Charles on 11-11-2.
//  Copyright 2011 hust. All rights reserved.
//

#import "BestScore.h"


@implementation BestScore

static 	int array[MAX_BEST_SCORE_TYPE_COUNT];

+(id) scoreWithType:(int)type
{
	return [[[self alloc] initWithType:type] autorelease];
}



-(id) initWithType:(int)type
{
	NSString * str=@"cMode_number.png";
	
	CCSprite * tmp=[CCSprite spriteWithFile:str];
	int w_txt=tmp.contentSize.width/10;
	int h_txt=tmp.contentSize.height;
	
	if ((self = [super initWithString:@"0" 
				 charMapFile:str
				 itemWidth:w_txt itemHeight:h_txt startCharMap:'0']))
	{

		
		
		 mType=type;
		NSAssert(mType<MAX_BEST_SCORE_TYPE_COUNT,"mType over range!");
		
		////////获取当前保存的游戏数据，最高分
		////[self initArray];  //////test
		///[FileRW WriteDemoFile:array Size:MAX_BEST_SCORE_TYPE_COUNT];  //////test
		
		[self updateCurBestScore];
		
	}
	
	return self;
}


+(void)initArray:(int *)Array Size:(int)size
{
	for (int i=0; i<MAX_BEST_SCORE_TYPE_COUNT; i++) 
	{
		array[i]=Array[i];
	}
}

///////////////////////////////
///////////////////////////////
///////////////////////////////

#pragma mark export interface
+(void)initArrayFromFile
{
	int IArray[MAX_BEST_SCORE_TYPE_COUNT]={0,0,0};
	[SecureFileRW readFile:IArray Size:MAX_BEST_SCORE_TYPE_COUNT
					  path:[SecureFileRW dataFilePath]];   //read from file
	
	[BestScore initArray:IArray Size:MAX_BEST_SCORE_TYPE_COUNT]; 
}


+(void)saveArrayToFile
{
	[SecureFileRW WriteFile:array Size:MAX_BEST_SCORE_TYPE_COUNT
					path:[SecureFileRW dataFilePath]];
}


#pragma mark end of export interface

///////////////////////////////
///////////////////////////////
///////////////////////////////

-(NSString *)getCurTypeBestScoreString
{
	NSString * str=[NSString stringWithFormat:@"%d",array[mType]];
	return str;
}


-(int)getCurBestScore
{
	return array[mType];
}

-(int)setCurBestScore:(int)s
{
	array[mType]=s;
}

-(void)setBestScoreByType:(int)type andScore:(int)Score
{
	NSAssert(type<MAX_BEST_SCORE_TYPE_COUNT,"type over range!");
	array[type]=Score;
	
}


-(int)getBestScoreByType:(int)type
{
	NSAssert(type<MAX_BEST_SCORE_TYPE_COUNT,"type over range!");
	return array[type];
}

-(void)updateCurBestScore
{
	[self setString:[self getCurTypeBestScoreString]];
}


@end
